# -- coding: utf-8 --
# @time : 2023/7/3
# @author : 周梦泽
# @file : end_thread.py
# @software: pycharm
# 结束线程模块
import ctypes
import inspect


def async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed"""

    tid = ctypes.c_long(tid)
    if not inspect.isclass(exctype):
        exctype = type(exctype)
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
    if res == 0:
        # pass
        raise ValueError("错误线程id, 请重试")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble,
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
        raise SystemError("结束失败，请重试")







